class wordCounter {
  constructor(_vscode) {
    this.vscode = _vscode
    this.init()
  }
  init() {
    let vscode = this.vscode
    let StatusBarAlignment = vscode.StatusBarAlignment
    let window = this.vscode.window
    // 看不太懂的步骤
    // 1.手动释放statusbar
    this.statusBar = window.createStatusBarItem(StatusBarAlignment.Left)
    // 2. 释放跟注册事件相配合的数组
    let disposable = []
    // 3. 注册事件时自动填充一个回调dispose到数组
    window.onDidChangeTextEditorSelection(this.updateText, this, disposable)
    // 4.保存需要释放的资源
    this.disposable = vscode.Disposable.from(disposable)
    this.updateText()
    this.statusBar.show()
  }
  updateText() {
    let window = this.vscode.window
    this.editor = window.activeTextEditor
    let content = this.editor.document.getText()
    let len = content.length
    this.statusBar.text = `嘻嘻。。你敲了${len}个字了`
  }
  dispose() {
    this.disposable.dispose()
    this.statusBar.dispose()
  }
}

module.exports = wordCounter